<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<!-- 8. 字数统计  -->

<body>
  <div id="app">
    <textarea v-model="text" @input="item" placeholder="请输入内容"></textarea>
    <p>剩余字数：{{ 10 - text.length }}</p>
  </div>
</body>
<script src="./vue.js"></script>
<script>
  const { createApp, ref } = Vue;
  createApp({
    setup() {
      let text = ref('');
      function item() {
        if (text.value.length > 10) {
          text.value = text.value.slice(0, 10)
        }
      }
      return {
        text,
        item
      }
    }
  }).mount('#app')
</script>

</html>